package org.jeecg.modules.middle.datas.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.manage.entity.CaishuiWithdraw;
import org.jeecg.modules.middle.datas.service.ICaishuiWithdrawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
* @Description: 账户提现[中台]
* @Author: yfkj
* @Date:   2023-02-22
* @Version: V1.0
*/
@Api(tags="账户提现[中台]")
@RestController
@RequestMapping("/datas/caishuiWithdraw")
@Slf4j
public class CaishuiWithdrawController extends JeecgController<CaishuiWithdraw, ICaishuiWithdrawService> {

   @Autowired
   private ICaishuiWithdrawService caishuiWithdrawService;

   /**
    * 分页列表查询
    *
    * @param caishuiWithdraw
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @ApiOperation(value="账户提现[中台]-分页列表查询", notes="账户提现[中台]-分页列表查询")
   @GetMapping(value = "/list")
   public Result<IPage<CaishuiWithdraw>> queryPageList(CaishuiWithdraw caishuiWithdraw,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<CaishuiWithdraw> queryWrapper = QueryGenerator.initQueryWrapper(caishuiWithdraw, req.getParameterMap());
       //当前登录用户
       LoginUser loginUser = TokenUtils.getLoginUser();
       if(loginUser.getUserType()==2 && loginUser.getMiddleOptAuth()==2){//中台渠道角色
           queryWrapper.lambda().eq(CaishuiWithdraw::getChannelBusinessId,loginUser.getChannelBusinessId());
           if(loginUser.getMiddleUserType()==2){//员工
               queryWrapper.lambda().eq(CaishuiWithdraw::getUserId,loginUser.getId());
           }
       }
       Page<CaishuiWithdraw> page = new Page<CaishuiWithdraw>(pageNo, pageSize);
       IPage<CaishuiWithdraw> pageList = caishuiWithdrawService.page(page, queryWrapper);
       return Result.OK(pageList);
   }

   /**
   * 导出excel
   *
   * @param request
   * @param caishuiWithdraw
   */
   @RequestMapping(value = "/exportXls")
   public ModelAndView exportXls(HttpServletRequest request, CaishuiWithdraw caishuiWithdraw) {
       //当前登录用户
       LoginUser loginUser = TokenUtils.getLoginUser();
       if(loginUser.getUserType()==2 && loginUser.getMiddleOptAuth()==2){//中台渠道角色
           caishuiWithdraw.setChannelBusinessId(loginUser.getChannelBusinessId());
           if(loginUser.getMiddleUserType()==2){//员工
               caishuiWithdraw.setUserId(loginUser.getId());
           }
       }
       return super.exportXls(request, caishuiWithdraw, CaishuiWithdraw.class, "账户提现[中台]");
   }

}
